require(['./config'],()=>{
    require(['template','header','footer'],(template)=>{  //依赖于header模块 header模块又将header.HTML中的文件给加载出来
        class infoPage{
            constructor(){
                
               this.getList().then(
                   
               )
            }
            getList(){
                
                return new Promise((resolve,reject)=>{
                    const id = location.search.split("=")[1];

                    console.log(id)     
                    //进入这个网页 先发送请求 获取导航栏
                    $.get(`http://www.xiongmaoyouxuan.com/api/column/${id}`,{start:0},resp=>{
                        if(resp.code == 200){
                            
                            var data = resp.data;
                            
                            
                            $('.main-wrap').html(template('wrap-con',{data}));
                                  
                            //点击导航栏 比如9.9专区 一进来就要直接请求第一条数据 默认渲染
                            //某些导航栏没有小导航栏 判断重新请求一下数据渲染
                            if($('.main-wrap-link-top').find("dl dd:first-child").attr("class")){
                                $.get(`http://www.xiongmaoyouxuan.com/api/sub_column/${$('.main-wrap-link-top').find("dl dd:first-child").attr("class")}/items`,{start:0},resp=>{
                                        if(resp.code==200){
                                            var list = resp.data.list;
                                            console.log(list)
                                            $('.main-wrap-shoplist-ul').html(template('shoplist-ul',{list}));
                                        }
                                })
                            }else{
                                //http://www.xiongmaoyouxuan.com/api/column/3183/items?start=0
                                $.get(`http://www.xiongmaoyouxuan.com/api/column/${id}/items`,{start:0},resp=>{
                                        if(resp.code==200){
                                            var list = resp.data.list;
                                            console.log(list)
                                            $('.main-wrap-shoplist-ul').html(template('shoplist-ul',{list}));
                                        }
                                })
                            }
                            
                            

                            //点击小导航栏 渲染数据
                            $('.main-wrap-link-top dd').on('click',function(){
                                    $.get(`http://www.xiongmaoyouxuan.com/api/sub_column/${$(this).attr('class')}/items`,{start:0},resp=>{
                                        if(resp.code==200){
                                            var list = resp.data.list;
                                            console.log(list)
                                            $('.main-wrap-shoplist-ul').html(template('shoplist-ul',{list}));
                                        }
                                })
                            })
                        }
                    })
                    resolve()
                })
            } 
        }
         new infoPage();
    })
})